import React from 'react';
import moment from 'moment';
import { connect } from 'dva';
import _ from 'lodash';
import LabelList from '../../../components/labelList';
import styles from './index.less';

function StoreInfo(props) {
    const { data, viewType, areaData, user } = props;
    if (viewType === 0) {
        const normalize = [
            ['name', '店铺名称'],
            ['employee', '店主姓名'],
            ['deposit', '押金(元)'],
            ['gatheringName', '合作形式'],
            ['regionName', '所在区域'],
            ['area', '所在地址', (values) => {
                const [a, b, c] = values;
                const area0 = _.find(areaData, ['value', a]);
                const area1 = _.find(area0.children, ['value', b]);
                const area2 = _.find(area1.children, ['value', c]);
                return [area0.label, area1.label, area2.label].join(' ');
            }],
            ['address', '详细地址'],
            ['mobile', '联系电话'],
            ['status', '状态', (v) => {
                return v === 1 ? '正常' : '暂停';
            }],
        ];
        const normalize2 = [
            ['createTime', '创建日期', t => moment(t).format('YYYY-MM-DD HH:mm:ss')],
            ['updateTime', '更新日期', t => moment(t).format('YYYY-MM-DD HH:mm:ss')],
        ];
        if (!data || data.length < 1) {
            return (
                <div
                    style={{
                        textAlign: 'center',
                    }}
                >
                    <br />
                    您没有店铺信息
                </div>
            );
        }
        return (
            <div className={styles.normal}>
                <LabelList
                    data={data}
                    align="left"
                    normalize={normalize}
                />
                <LabelList
                    data={user}
                    align="left"
                    normalize={normalize2}
                />
            </div>
        );
    }
}

function mapStateToProps({ store, app: { user } }) {
    return { ...store, user };
}

export default connect(mapStateToProps)(StoreInfo);
